// packageI/tagCloud/components/foot.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: null,
      value: []
    },
    footer: {
      type: null,
      value: {}
    },
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      this.getiPnoneBottom();
     
    },
    moved() {},
    detached() {},
  },

  /**
   * 组件的初始数据
   */
  data: {
    iPnoneBottomBol: false,
    showCircle: false,
    loadCircle: true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    gotoUrl(e){
      let _link = e.currentTarget.dataset.link;
      if(!_link) return;
      try {
        wx.navigateTo({
          url: _link
        });
      } catch (error) {
        wx.reLaunch({
          url: _link
        });
      }
    },
    goTo(e) {
      let id = e.currentTarget.dataset.id;
      switch (id) {
        case "1":
          wx.navigateTo({
            url: "/packageG/index/index",
          });
          break;
        case "2":
            wx.navigateTo({
              url: "/packageG/pages/category_v2/category_v2",
            });
          break;
        case "3":
          if(this.data.loadCircle) this.getTop()
          this.setData({
            showCircle: !this.data.showCircle
          })
          break;
        case "4":
            wx.navigateTo({
              url: "/packageG/pages/buy/cart_v2/cart_v2",
            });
          break;
        case "5":
          wx.navigateTo({
            url: "/packageG/member_v2/member_v2",
          });
          break;
        default:
          console.log("error");
      }
    },
    getiPnoneBottom() {
      let that = this;
      try {
        var value = wx.getStorageSync("iPhoneBottom");
        if (value) {
          that.setData({
            iPnoneBottomBol: true,
          });
          // Do something with return value
        }
      } catch (e) {
        // Do something when catch error
      }
    },


    getPi() {
      const PI = 3.1415926535
      let angle = 0;
      let R = 180;
      let n = 5;
      let top = 0;
      let left = 0;

      angle = 180 / n;

      for (let i = 0; i < n; i++) {
        let ang = i * angle * PI / 90;
        if (ang >= 0 && ang < PI / 2) {
          top = R - R * Math.cos(ang);
          left = R + R * Math.sin(ang);
        }
        if (ang >= PI / 2 && ang < PI) {
          top = R + R * Math.cos(ang);
          left = R - R * Math.sin(ang);
        }
        if (ang >= PI && ang <= PI * 3 / 2) {
          top = R - R * Math.cos(ang);
          left = R + R * Math.sin(ang);
        }
        if (ang >= PI * 3 / 2 && ang <= PI * 2) {
          top = R + R * Math.cos(ang);
          left = R - R * Math.sin(ang);
        }
        console.log(top, left)
      }
      return 0;
    },
    getCirclePosition({
      x,
      y,
      r,
      nodeNum,
      nodeIndex,
      changeAngle
    }) {
      // 获取平分的角度
      let angle = 180 / nodeNum;
      // 获取当前角度值
      let currentAngle = angle * nodeIndex;
      // 调整这个角度，即可变换初始角度
      let _angle = ['','270','225','210','200','200']
      // if (changeAngle) {
        currentAngle = currentAngle + Number(_angle[this.data.list.length]);
      // }
      // 圆上点的x_
      let x_ = x + r * Math.cos((currentAngle * Math.PI) / 180);
      // 圆上点的y_
      let y_ = y + r * Math.sin((currentAngle * Math.PI) / 180);

      return {
        x_,
        y_
      }
    },

    getTop() {
      // 圆弧上点的个数
      let len = this.data.list.length;
      let list = this.data.list
      for (let i = 0; i <= len-1; i++) {
        let position = this.getCirclePosition({
          x: 125,
          y: 125,
          r: 125,
          nodeNum: len,
          nodeIndex: i,
          
        })
        let left = (position.x_ - 10) + 'px';
        let top = (position.y_ - 10) + 'px';
        this.data.list[i].top = top;
        this.data.list[i].left = left;
      }
      this.setData({
        loadCircle: false,
        list: list
      })
    },
    onClickHide(){
      this.setData({
        showCircle: false
      })
    }
  },

});